﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	
	<script type="text/javascript">
		var onBackup = function () 
		{
			window.location.href='<c:url value='/dataBackupAndLoad/backup.html' />';
		}
		var showLoadWindow = function () 
		{
			//$('#dlg-dataBackupAndLoadForm').dialog('open').dialog('setTitle', '<spring:message code="backupAndRestore.restore.selectFile" />');
			$('#dlg-dataBackupAndLoadForm #backupFile').click();
		}
		var onSubmit = function() 
		{
			/*$.ajax({
		        url: '<c:url value='/dataBackupAndLoad/load.html' />',
		        type: 'post',
		        dataType: 'json',
		        data: $('#dlg-dataBackupAndLoadForm' + ' form').serialize(),
				beforeSend: 
					function (){
						return $('#dlg-dataBackupAndLoadForm' + ' form').form('validate');
					},
		        success: function(result){
		        	console.log(result);
					if (result.statusCode == '400' || result.statusCode == '500') {
						showFailureMsg (result.message);
					} else {
						showSuccessMsg (result.message);
						$('#dlg-dataBackupAndLoadForm' + ' form').form('clear');
						$('#dlg-dataBackupAndLoadForm').dialog('close'); // close the dialog  
					}
		        }
		    });*/
		    
			$('#dlg-dataBackupAndLoadForm').dialog('close');
			$('body').mask('<spring:message code="doing" />');
			$('#dlg-dataBackupAndLoadForm' + ' form').form('submit', {
				url : '<c:url value='/dataBackupAndLoad/load.html' />',
				onSubmit : function() {
					var filename = $('#dlg-dataBackupAndLoadForm #backupFile').val();
					var fileExtension = filename.substring(filename.lastIndexOf('.'));
					//console.log(fileExtension);
					if(fileExtension == '' || '.sqlbak' != fileExtension) 
					{
						$('body').unmask();
						showWarningMsg("必须是文件扩展名为'.sqlbak'的备份文件!");
						return false;
					}
					return $(this).form('validate');
				},
				success : function(result) {
					$('#dlg-dataBackupAndLoadForm' + ' form').form('clear');
					$('body').unmask();
					var result = eval('(' + result + ')');
					//console.log(result);
					if (result.statusCode == '400' || result.statusCode == '500') 
					{
						showFailureMsg (result.message);
					} 
					else 
					{
						showSuccessMsg (result.message);
					}
				}
			});
		}
	</script>
	
	<div style="text-align:center;">
		<div class="demo-info" style="margin: 0 auto; width:400px">
			<div class="demo-tip icon-tip"></div>
			<div><spring:message code="backupAndRestore.backup.info" /></div>
			<div class="demo-tip icon-tip"></div>
			<div><spring:message code="backupAndRestore.restore.info" /></div>
		</div>
		<div id="dataBackupAndLoad-div" style="height:100px; margin-top:20px;">
			<a id="" href="javascript:void(0)" class="easyui-linkbutton" style="width:100px" data-options="size:'large'" 
				iconCls="icon-redo" onclick="onBackup()" title="<spring:message code="backupAndRestore.backup.tip" />"><spring:message code="backupAndRestore.backup" /></a> 
			<a href="javascript:void(0)" class="easyui-linkbutton" style="width:100px" data-options="size:'large'" 
				iconCls="icon-back" onclick="showLoadWindow()" title="<spring:message code="backupAndRestore.restore.tip" />"><spring:message code="backupAndRestore.restore" /></a>
		</div>
	</div>
	
	<div id="dlg-dataBackupAndLoadForm" class="easyui-dialog" 
		style="width: 350px; height: 250px; padding: 10px 20px" closed="true" 
		data-options="modal:true" buttons="#dlg-dataBackupAndLoadForm-btns">
		<form method="post" enctype="multipart/form-data">
			<input type="file" name="backupFile" id="backupFile" onchange="onSubmit()" />
		</form>
	</div>
	<div id="dlg-dataBackupAndLoadForm-btns">
		<a href="javascript:void(0)" id="saveBtn" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="onSubmit()"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-dataBackupAndLoadForm').dialog('close')"><spring:message code="cancel" /></a>
	</div>
